package com.otp.webapp.comparators;

import java.util.Comparator;

import com.otp.model.test.instance.TestItemResponseInstance;

public class CompTestItemResponseInstancesBySectionAndOrderInSection 
implements Comparator<TestItemResponseInstance>{
	
	public int compare(TestItemResponseInstance ri1, TestItemResponseInstance ri2){
		int section1 = (int) (long) ri1.getRelatedItem().getTestSection().getOrderInTest();
		int section2 = (int) (long) ri2.getRelatedItem().getTestSection().getOrderInTest();

		if(section1==section2){
			int orderInSection1 = ri1.getRelatedItem().getOrderInSection();
			int orderInSection2 = ri2.getRelatedItem().getOrderInSection();
			return orderInSection1 - orderInSection2;
		}
		
		return section1 - section2;

	}

}
